<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>综合服务系统--试题库新增</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/supplier/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <link rel="stylesheet" href="/plugin/it/common/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <#--	<link rel="stylesheet" href="${re.contextPath}/plugin/zTree/CSS/tree.css" type="text/css">-->
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/zTree/js/jquery.ztree.all.js" charset="utf-8"></script>
</head>
<style>
    .Right {
        width: 100%;
        overflow-y: auto;
    }

    .screening ul li:nth-child(1) select, .screening ul li:nth-child(3) select, .screening ul li:nth-child(6) select {
        width: 30%;
    }

    .layui-breadcrumb a:hover {
        color: #5775EF !important;
    }

    .layui-form-radio > i:hover, .layui-form-radioed > i {
        color: #5775EF;
    }

    .layui-form-radio {
        margin: 0;
        padding: 0;
    }

    .layui-btn-normal {
        background: #5775EF;
    }

    .screening button {
        width: 100px;
    }

    .layui-form-checkbox i {
        border: 1px solid #d2d2d2;
    }

    .layui-form-checked i, .layui-form-checked:hover i {
        color: #5775EF;
    }
</style>

<body>
<!--头部-->
<div style="background-color: #F1F4FB;padding-left: 20px;">
    <span class="layui-breadcrumb" lay-separator=">">
        <a><cite>考试管理</cite></a>
        <a href="/ex/question/stkIndex"><cite>试题库</cite></a>
        <a href="#"><cite>新增试题</cite></a>
    </span>
</div>
<!--容器-->
<div class="container clearfix">
    <!--右侧内容-->
    <#--    <div class="Right fr mt10">-->
    <#--        <div class="layui-container ztree">-->
    <#--            <ul id="treeDemo"></ul>-->
    <#--        </div>-->
    <#--    </div>-->
    <div class="Right fr">
        <form class="layui-form" enctype="multipart/form-data">
            <div class="screening screeningOne whitebg clearfix" style="margin-top: 0;">
                <div class="bold">试题设置</div>
                <ul class="clearfix fl" style="width: 100%;">
<#--                    <li style="width: 30%;">
                        <label class="fl"><span class="red">*</span>试题分类：</label>
                        <select name="quCategory" class="ml8 " style="width: 40%;padding: 0 0 0 3;"
                                id="quCategory" lay-verify="required"
                                lay-ignore>
                            <option value="">请选择</option>
                            <#list stfl as vo>
                                <option value="${vo.badtCode}" class="stfl"
                                >${vo.badtName}</option>
                            </#list>
                        </select>
                    </li>-->
                    <li style="width: 30%;" hidden>
                        <label class="fl"><span class="red">*</span>试题分类：</label>
                        <input name="quCategory" class="ml8 " style="width: 40%;padding: 0 0 0 3;"
                                id="quCategory"
                                lay-ignore>
                        </input>
                    </li>

                    <li style="width: 30%;">
                        <div class="layui-form-item">
                            <label class="fl"><span class="red">*</span>试题分类：</label>
                            <div class="layui-input-inline">
                                <div class="layui-unselect layui-form-select downpanel">
                                    <div class="layui-select-title" >
                                        <input lay-verify="required" class="layui-input layui-unselect" style="border:0.5px solid rgba(191,191,191,0.8)" id="treeclass" autocomplete="off" placeholder="请选择分类"></input>
                                        <i class="layui-edge"></i>
                                    </div>
                                    <dl class="layui-anim layui-anim-upbit">
                                        <dd>
                                            <ul id="classtree"></ul>
                                        </dd>
                                    </dl>
                                </div>
                            </div>
                        </div>
                    </li>

                    <li style="width: 30%">
                        <label class="fl"><span class="red">*</span> 试题类型：</label>
                        <select name="quType" class="ml8 " style="width: 40%;padding: 0 0 0 3;" id="quType"
                                onchange="lxChange(this)" lay-verify="required"
                                lay-ignore>
                            <#list sttx as vo>
                                <option value="${vo.badtCode}" class="question-type"
                                >${vo.badtName}</option>
                            </#list>
                        </select>
                    </li>
                    <li style="width: 30%;">
                        <label class="fl"><span class="red">*</span> 试题难度：</label>
                        <select name="level" class="ml8 " style="width: 40%;padding: 0 0 0 3;" id="level"
                                lay-verify="required"
                                lay-ignore>
                            <option value="">请选择</option>
                            <#list stnd as vo>
                                <option value="${vo.badtCode}" class="qulvl"
                                >${vo.badtName}</option>
                            </#list>
                        </select>
                    </li>
                </ul>
                <div class="bold"><span class="red">*</span>题目名称</div>
                <ul class="clearfix fl" style="width: 100%;">
                    <textarea id="content" lay-verify="content" name="content" style="display: none;"></textarea>
                </ul>
                <#--            单选题-->
                <div id="dx">
                    <div id="dxs">
                        <div class="bold"><span class="red">*</span>选项(从选项中选择一个作为答案)</div>
                        <ul class="clearfix fl dx addInfo" style="width: 100%;">
                            <input type="radio" name="exDxList[0].isItRight"
                                   style="display: none;" class="fl h30 w25 doBestInput"
                                   value="A"><span>A</span>、<span>答案</span>
                            <textarea id="dx0" lay-verify="content" name="exDxList[0].answerAnalysis"></textarea>
                            <input type="hidden" name="exDxList[0].answerContent" value="A">
                        </ul>
                        <ul class="clearfix fl dx addInfo" style="width: 100%;">
                            <input type="radio" name="exDxList[0].isItRight"
                                   style="display: none;" class="fl h30 w25 doBestInput"
                                   value="B"><span>B</span>、<span>答案</span>
                            <textarea id="dx1" lay-verify="content" name="exDxList[1].answerAnalysis"></textarea>
                            <input type="hidden" name="exDxList[1].answerContent" value="B">
                        </ul>
                    </div>
                    <#--				<ul class="clearfix fl"  style="width: 100%;">-->
                    <#--					<span style="float: left" name="exDxList[0].answerContent" value="A">A</span><input type="radio" name="exDxList[0].isRight"  class="fl h30 w25 doBestInput" value="A"><span>答案</span>-->
                    <#--					<textarea id="demo1" style="display: none;" name="exDxList[0].answerAnalysis"></textarea>-->
                    <#--				</ul>-->
                    <#--				<ul class="clearfix fl"  style="width: 100%;">-->
                    <#--					<span style="float: left" name="exDxList[1].answerContent" value="B">B</span><input type="radio" name="exDxList[0].isRight"  class="fl h30 w25 doBestInput"  value="B"><span>答案</span>-->
                    <#--					<textarea id="demo2" style="display: none;" name="exDxList[1].answerAnalysis"></textarea>-->
                    <#--				</ul>-->
                    <#--				<ul class="clearfix fl"  style="width: 100%;">-->
                    <#--					<span style="float: left" name="exDxList[2].answerContent" value="C">C</span><input type="radio" name="exDxList[0].isRight" class="fl h30 w25 doBestInput"  value="C"><span>答案</span>-->
                    <#--					<textarea id="demo3" style="display: none;" name="exDxList[2].answerAnalysis"></textarea>-->
                    <#--				</ul>-->
                    <#--				<ul class="clearfix fl"  style="width: 100%;">-->
                    <#--					<span style="float: left" name="exDxList[3].answerContent" value="D">D</span><input type="radio"  name="exDxList[0].isRight" class="fl h30 w25 doBestInput" value="D"><span>答案</span>-->
                    <#--					<textarea id="demo4" style="display: none;" name="exDxList[3].answerAnalysis"></textarea>-->
                    <#--				</ul>-->
                    <div class="col-md-2 layui-col-md-offset5 layui-btn-normal bluebg cursor"
                         style="display: inline-block; width: 200px; padding: 0 20px; height: 50px; line-height: 50px;border-radius: 3px;margin-top: 10px;margin-left: calc(50% - 120px);"
                         onclick="addDx()">
                        <img src="${re.contextPath}/plugin/common/images/add-white.png"
                             alt="" class="cursor"
                             style="width:30px; margin: 10px;">
                        <span class="white">添加一个新的选项</span>
                    </div>
                </div>
                <#--多选题-->
                <div id="duox">
                    <div class="bold"><span class="red">*</span>选项(从选项中选择一个作为答案)</div>
                    <ul class="clearfix fl duox" style="width: 100%;">
                        <input type="checkbox" name="exDuoxList[0].isItRight"
                               style="display: none;" class="fl h30 w25 doBestInput"
                               value="A"><span>A</span>、<span>答案</span>
                        <textarea id="duox0" lay-verify="content" name="exDuoxList[0].answerAnalysis"></textarea><input
                                type="hidden" name="exDuoxList[0].answerContent" value="A">
                    </ul>
                    <ul class="clearfix fl duox" style="width: 100%;">
                        <input type="checkbox" name="exDuoxList[1].isItRight"
                               style="display: none;" class="fl h30 w25 doBestInput"
                               value="B"><span>B</span>、<span>答案</span>
                        <textarea id="duox1" lay-verify="content" name="exDuoxList[1].answerAnalysis"></textarea><input
                                type="hidden" name="exDuoxList[1].answerContent" value="B">
                    </ul>
                    <div id="duoxs"></div>
                    <div class="col-md-2 layui-col-md-offset5  layui-btn-normal bluebg cursor"
                         style="margin-top: 10px;display: inline-block; width: 200px; padding: 0 20px; height: 50px; line-height: 50px;border-radius: 3px;margin-top: 10px;margin-left: calc(50% - 120px);"
                         onclick="addDuox()">
                        <img src="${re.contextPath}/plugin/common/images/add-white.png"
                             alt="" class="cursor"
                             style="width:30px; margin: 10px;">
                        <span class="white">添加一个新的选项</span>
                    </div>
                </div>
                <#--			判断题-->
                <div id="pd">
                    <div class="bold"><span class="red">*</span>选项(从选项中选择一个作为答案)</div>
                    <ul class="clearfix fl" style="width: 100%;">
                        <input type="radio" name="exPdList[0].isItRight" value="√" title="√">
                        <input type="radio" name="exPdList[0].isItRight" value="×" title="×">
                        <input type="text" name="exPdList[0].answerContent" value="√" style="display:none">
                        <input type="text" name="exPdList[1].answerContent" value="×" style="display:none">
                    </ul>
                </div>
                <#--			填空题-->
                <div id="tk">
                    <div class="bold"><span class="red">*</span>答案</div>
                    <ul class="clearfix fl tk" style="width: 100%;">
                        <label class="fl w90" style="float: left">填空1</label><input type="text"
                                                                                    name="exTkList[0].answerContent"
                                                                                    placeholder="请输入内容">
                        <input type="hidden" name="exTkList[0].answerAnalysis" value="填空1">
                    </ul>
                    <div id="tks">
                    </div>
                    <div class="col-md-2 layui-col-md-offset5  layui-btn-normal bluebg cursor"
                         style="display: inline-block; width: 200px; padding: 0 20px; height: 50px; line-height: 50px;border-radius: 3px;margin-top: 10px;margin-left: calc(50% - 120px);"
                         onclick="addTk()">
                        <img src="${re.contextPath}/plugin/common/images/add-white.png"
                             alt="" class="cursor"
                             style="width:30px; margin: 10px;">
                        <span class="white">添加一个新的填空</span>
                    </div>
                </div>
                <#--			问答题-->
                <div id="wd">
                    <div class="bold"><span class="red">*</span>问题答案</div>
                    <ul class="clearfix fl" style="width: 100%;">
                        <textarea id="wdt" lay-verify="content" name="exWdList[0].answerContent"></textarea>
                    </ul>
                </div>
                <div class="bold">解析</div>
                <ul class="clearfix" style="width: 100%;">
                    <textarea id="analysis" name="analysis" style="display: none;"></textarea>
                </ul>
                <div class="releaseBtn center" style="margin-top: 10px;">
                    <#--				<button type="submit" lay-submit lay-filter="cancel" class="layui-btn layui-btn-normal white ft18 " id="">取消</button>-->
                    <button type="button" class="layui-btn layui-btn-normal white ft18 close">返回</button>
                    <button type="submit" lay-submit lay-filter="save"
                            class="layui-btn layui-btn-normal bluebg white ft18 " id="btnsave">保存
                    </button>
                    <#if '${fix}'!='1'>
                        <button type="submit" lay-submit lay-filter="submit"
                                class="layui-btn layui-btn-normal bluebg white ft18" id="btnsubmit">提交
                        </button>
                    </#if>
                    <button type="submit" lay-submit lay-filter="saves"
                            class="layui-btn layui-btn-normal bluebg white ft18 " id="btnsaves">保存并添加
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/tabs.js"></script>
<script type="text/javascript">
    // $(".addInfo").find("div:eq(0)").css({
    // 	"display":"none"
    // })

    var layer;
    var form;
    var table = null;
    var tableIns = null;
    var layedit;
    var varter = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
    //注意进度条依赖 element 模块，否则无法进行正常渲染和功能性操作
    var element;
    layui.use(['element', 'laydate', 'layedit', 'form','tree'], function () {
        element = layui.element;
        form = layui.form;
        tree = layui.tree;
        layedit = layui.layedit;
        // var content = layedit.build('content',{
        //     tool: [ 'strong','italic','underline','del', '|','left', 'center', 'right']
        // }); //建立编辑器
        var content = layedit.build('content', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
        }); //建立编辑器
        var analysis = layedit.build('analysis', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
        }); //建立编辑器 //建立编辑器
        var wdt = layedit.build('wdt', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
        }); //建立编辑器
        var dx0 = layedit.build('dx0', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
        }); //建立编辑器
        var dx1 = layedit.build('dx1', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
        }); //建立编辑器
        var duox0 = layedit.build('duox0', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
        }); //建立编辑器
        var duox1 = layedit.build('duox1', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
        }); //建立编辑器
        window.check = function (bjq) {
            layedit.build(bjq, {
                tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
            });
        };

        /*处理试题分类-树显示*/
        var treeDto = [];
        /*执行查询分类*/
        $(function (){
            layerAjaxGet('/ex/question/selectTypeClassifyQu', {}, '', function (res) {
                if (200 == res.code){
                    treeDto = res.data;
                    tree.render({
                        elem: "#classtree",
                        data: treeDto,
                        click: function (node) {
                            /*当前选择的回显*/
                            $('#treeclass').val(node.data.title);
                            /*回显隐藏id*/
                            $('#quCategory').val(node.data.id)
                            var $select = $($(this)[0].elem).parents(".layui-form-select");
                            $select.removeClass("layui-form-selected").find(".layui-select-title span").html(node.name).end().find("input:hidden[name='selectID']").val(node.id);
                        }
                    });
                }
            })
        })
        /*点击输入框*/
        $(".downpanel").on("click", ".layui-select-title", function (e) {
            $(".layui-form-select").not($(this).parents(".layui-form-select")).removeClass("layui-form-selected");
            $(this).parents(".downpanel").toggleClass("layui-form-selected");
            layui.stope(e);
        }).on("click", "dl i", function (e) {
            // 点击展开菜单
            layui.stope(e);
        });
        /*这个是点击的那个*/
        $(document).on("click", function (e) {
            $(".layui-form-select").removeClass("layui-form-selected");
        });

        form.verify({
            //content富文本域中的lay-verify值
            content: function (value) {
                layedit.sync(content);
                layedit.sync(analysis);
                layedit.sync(wdt);
                layedit.sync(dx0);
                layedit.sync(dx1);
                layedit.sync(duox0);
                layedit.sync(duox1);
                //单选和多选的富文本
                var index = $("textarea").length;
                $(".layui-layedit-iframe").find("iframe").each(function (i,v){
                    var  id=$(v).attr("id");
                   var  idnum= id.replaceAll("LAY_layedit_","");
                    layedit.sync(idnum);
                });
            }
        });
        //保存
        form.on('submit(save)', function (data) {
            var datas = data.field;
            // datas.content = layedit.getContent(content);
            // datas.analysis = layedit.getContent(analysis);
            if (!datas.content) {
                layer.msg("题目名称不能为空", {icon: 2});
                return false;
            }
            datas.status = '001';
            layerAjax("/ex/question/insertSt", datas, '', function (d) {
                if (d.flag) {
                    layer.msg("保存成功！", {icon: 1});
                    //点击一次后关闭按钮
                    $('#btnsaves').addClass("layui-btn-disabled").attr("disabled", true);
                    $('#btnsubmit').addClass("layui-btn-disabled").attr("disabled", true);
                    $('#btnsave').addClass("layui-btn-disabled").attr("disabled", true);
                    setTimeout(function () {
                        window.parent._showtab('5253b2f369364ceca7dbca94a85b68ca', '试题库', '/ex/question/stkIndex');
                    }, 1000)
                } else {
                    layer.msg(d.msg, {icon: 2});
                    // $('#btnsaves').addClass("layui-btn-disabled").attr("disabled", false);
                    // $('#btnsubmit').addClass("layui-btn-disabled").attr("disabled", false);
                    // $('#btnsave').addClass("layui-btn-disabled").attr("disabled", false);
                    return false;
                }
            })
            return false;
        });
        //提交
        form.on('submit(submit)', function (data) {
            var datas = data.field;
            // datas.content = layedit.getContent(content);
            // datas.analysis = layedit.getContent(analysis);
            if (!datas.content) {
                layer.msg("题目名称不能为空", {icon: 2});
                return false;
            }
            datas.status = '002';
            layerAjax("/ex/question/insertSt", datas, '', function (d) {
                if (d.flag) {
                    layer.msg("提交成功！", {icon: 1});
                    //点击一次后关闭按钮
                    $('#btnsaves').addClass("layui-btn-disabled").attr("disabled", true);
                    $('#btnsubmit').addClass("layui-btn-disabled").attr("disabled", true);
                    $('#btnsave').addClass("layui-btn-disabled").attr("disabled", true);
                    setTimeout(function () {
                        window.parent._showtab('5253b2f369364ceca7dbca94a85b68ca', '试题库', '/ex/question/stkIndex');
                    }, 1000)
                } else {
                    layer.msg(d.msg, {icon: 2});
                    // $('#btnsaves').addClass("layui-btn-disabled").attr("disabled", false);
                    // $('#btnsubmit').addClass("layui-btn-disabled").attr("disabled", false);
                    // $('#btnsave').addClass("layui-btn-disabled").attr("disabled", false);
                    return false;
                }
            })
            return false;
        });
        //保存并添加
        form.on('submit(saves)', function (data) {
            var datas = data.field;
            // datas.content = layedit.getContent(content);
            // datas.analysis = layedit.getContent(analysis);
            if (!datas.content) {
                layer.msg("题目名称不能为空", {icon: 2});
                return false;
            }
            datas.status = '001';
            sessionStorage.setItem("quCategory", datas.quCategory);
            sessionStorage.setItem("quType", datas.quType);
            sessionStorage.setItem("level", datas.level);
            layerAjax("/ex/question/insertSt", datas, '', function (d) {
                if (d.flag) {
                    layer.msg("保存成功！", {icon: 1});
                    //点击一次后关闭按钮
                    $('#btnsaves').addClass("layui-btn-disabled").attr("disabled", true);
                    $('#btnsubmit').addClass("layui-btn-disabled").attr("disabled", true);
                    $('#btnsave').addClass("layui-btn-disabled").attr("disabled", true);
                    setTimeout(function () {
                        window.location.reload();
                    }, 1000)
                } else {
                    layer.msg(d.msg, {icon: 2});
                    return false;
                }
            })
            return false;
        });
    });
    //取消按钮
    $('.close').click(function () {
        window.parent._showtab('5253b2f369364ceca7dbca94a85b68ca', '试题库', '/ex/question/stkIndex');
    });

    var dx = $("#dx");
    var wd = $("#wd");
    var pd = $("#pd");
    var tk = $("#tk");
    var duox = $("#duox")
    $(function () {
        wd.hide();
        pd.hide();
        tk.hide();
        duox.hide();

        var quCategory = sessionStorage.getItem("quCategory");
        var quType = sessionStorage.getItem("quType");
        var level = sessionStorage.getItem("level");

        var stfl = $(".stfl");
        var qtype = $(".question-type");
        var qlvl = $(".qulvl");
        if(quCategory && quType && level){
/*            for (var i = 0; i < stfl.length; i++) {
                if (quCategory == stfl[i].getAttribute('value')) {
                    stfl[i].setAttribute('selected', 'selected',0);
                    sessionStorage.removeItem("quCategory");
                }
            }*/
            treeChecked(quCategory);

            for (var i = 0; i < qtype.length; i++) {
                if (quType == qtype[i].getAttribute('value')) {
                    qtype[i].setAttribute('selected', 'selected',0);
                    questiontype(quType);
                    sessionStorage.removeItem("quType");
                }
            }

            for (var i = 0; i < qlvl.length; i++) {
                if (level == qlvl[i].getAttribute('value')) {
                    qlvl[i].setAttribute('selected', 'selected',0);
                    sessionStorage.removeItem("level");
                }
            }
        }

        // lxChange()
    })

    /*编辑时，回显树形数据指定数据*/
    function treeChecked(stfl){
        layerAjaxGet('/ex/question/selectTypeClassifyQu', {}, '', function (res) {
            if (200 == res.code){
                var temp = res.data;
                for (var i = 0; i < temp.length; i++){
                    var oneId = temp[i]; // 第一级目录
                    if (oneId.id == stfl){
                        $('#treeclass').val(oneId.title);
                        $('#quCategory').val(oneId.id)
                        sessionStorage.removeItem("quCategory");
                        return;
                    }
                    if (oneId.children.length != 0){
                        for (var j = 0; j < oneId.children.length; j ++){
                            var twoId = oneId.children[j];
                            if (twoId.id == stfl){
                                $('#treeclass').val(twoId.title);
                                $('#quCategory').val(twoId.id)
                                sessionStorage.removeItem("quCategory");
                                return;
                            }
                        }
                    }
                }
            }
        })
    }

    //选择试题类型进行切换数据
    function lxChange(obj) {
        var code = $(obj).find('option:selected').val();

        questiontype(code);
    }

    function questiontype (code) {
        if (code == '001') {
            dx.show();
            wd.hide();
            pd.hide();
            tk.hide();
            duox.hide();
        } else if (code == '002') {
            duox.show();
            wd.hide();
            dx.hide();
            tk.hide();
            pd.hide();
        } else if (code == '003') {
            pd.show();
            wd.hide();
            dx.hide();
            tk.hide();
            duox.hide();
        } else if (code == '004') {
            tk.show();
            pd.hide();
            wd.hide();
            dx.hide();
            duox.hide();
        } else if (code == '005') {
            wd.show();
            dx.hide();
            tk.hide();
            pd.hide();
            duox.hide();
        }
    }

    //增加单选题
    function addDx() {

        var index = $(".dx").length;
        var dx = $("<ul class=\"clearfix fl dx\"  style=\"width: 100%;position: relative\">\n<input type=\"radio\" name=\"exDxList[0].isItRight\" style=\"display: none;\"  class=\"fl h30 w25 doBestInput\" value=\"" + varter[index] + "\"><div class=\'layui-unselect layui-form-radio\'><i class=\'layui-anim layui-icon\'></i><div></div></div>" +
            "\t\t\t\t\t<span>" + varter[index] + "</span>、<span class=\"da\">答案</span>\n" +
            "\t\t\t\t\t<textarea id=\"dx" + index + "\" class=\"dodx\" lay-verify=\"content\" name=\"exDxList[" + index + "].answerAnalysis\"></textarea><input type=\"hidden\" class='dxyc' name=\"exDxList[" + index + "].answerContent\" value=\"" + varter[index] + "\">\n" +
            "\t\t\t\t</ul>");
        var b = $("<img src=\"${re.contextPath}/plugin/common/images/30@2x.png\" onclick=\"delDx(this)\" style=\"position:absolute;top:35px;right:-20px;width:20px;height:20px;background-color:#3e7ce7\" alt=\"\" class=\"\">");
        b.click(delDx);
        var bjq = "dx" + index
        //延迟让标签先生成
        setTimeout(function () {
            dx.append(b)
            check(bjq);
        }, 1);
        $("#dxs").append(dx);

        form.render();

    }

    function delDx() {
        $(this).parent().remove();
        if ($(this).parent().length > 0) {
            var ssses = $("#dxs").find(".dodx");
            if (ssses.length > 0) {
                formatDXInd();
            }
        }
        form.render();

    }


    //删除后剩余重新排序
    function formatDXInd() {
        var dxs = $("#dxs");
        var ssses = dxs.find(".dodx");
        $.each(ssses, function (ind, obj) {
            // console.log(obj);
            // return;
            var oldAttrName = $(obj).attr('name');
            if (oldAttrName) {
                var front = oldAttrName.substring(0, oldAttrName.indexOf("[") + 1);
                var back = oldAttrName.substring(oldAttrName.indexOf("]"), oldAttrName.length);
                var newName = front + (ind + 2) + back;
                $(obj).attr('name', newName);
                $(obj).attr('id', "dx" + (ind + 2));
                $(obj).prev().prev().prev().prev().attr('value', varter[(ind + 2)]);
                $(obj).prev().prev().text(varter[(ind + 2)]);
                layedit.build("dx" + (ind + 2), {
                    tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
                });
            }
        })
        //遍历隐藏框
        var ssse = dxs.find(".dxyc");
        $.each(ssse, function (ind, obj) {
            var oldAttrName = $(obj).attr('name');
            if (oldAttrName) {
                var front = oldAttrName.substring(0, oldAttrName.indexOf("[") + 1);
                var back = oldAttrName.substring(oldAttrName.indexOf("]"), oldAttrName.length);
                var newName = front + (ind + 2) + back;
                $(obj).attr('name', newName);
                $(obj).attr('value', varter[(ind + 2)]);

            }
        })
    }

    //增加多选题
    function addDuox() {
        var index = $(".duox").length;
        var duox = $("<ul class=\"clearfix fl duox\"  style=\"width: 100%;position: relative\">\n<input type=\"checkbox\" name=\"exDuoxList[" + index + "].isItRight\" style=\"display: none;\" class=\"fl h30 w25 doBestInput\" value=\"" + varter[index] + "\"><div class=\'layui-unselect layui-form-checkbox\'><i class=\'layui-anim layui-icon\'></i><div></div></div>" +
            "\t\t\t\t\t<span class=\"answerContent\">" + varter[index] + "</span>、<span class=\"da\">答案</span>\n" +
            "\t\t\t\t\t<textarea id=\"duox" + index + "\" class=\"doduox\" lay-verify=\"content\" style=\"display: none;\" name=\"exDuoxList[" + index + "].answerAnalysis\"></textarea><input type=\"hidden\" class='duoxyc' name=\"exDuoxList[" + index + "].answerContent\" value=\"" + varter[index] + "\">\n" +
            "\t\t\t\t</ul>");
        var b = $("<img src=\"${re.contextPath}/plugin/common/images/30@2x.png\" style=\"position:absolute;top:35px;right:-20px;width:20px;height:20px;background-color:#3e7ce7\" onclick=\"delDuox(this)\" alt=\"\" class=\"\">");
        b.click(delDuox);
        var bjq = "duox" + index
        //延迟让标签先生成
        setTimeout(function () {
            duox.append(b)
            check(bjq);
        }, 1);
        $("#duoxs").append(duox);
        form.render();
    }

    function delDuox() {
        $(this).parent().remove();
        if ($(this).parent().length > 0) {
            var ssses = $("#duoxs").find(".doduox");
            if (ssses.length > 0) {
                formatDUOXInd();
            }
        }
        form.render();
    }

    //删除后剩余重新排序
    function formatDUOXInd() {
        var duoxs = $("#duoxs");
        var ssses = duoxs.find(".doduox");
        $.each(ssses, function (ind, obj) {
            var oldAttrName = $(obj).attr('name');
            var oldAttrNames = $(obj).prev().prev().prev().prev().attr('name');
            if (oldAttrName) {
                var front = oldAttrName.substring(0, oldAttrName.indexOf("[") + 1);
                var back = oldAttrName.substring(oldAttrName.indexOf("]"), oldAttrName.length);
                var newName = front + (ind + 2) + back;
                $(obj).attr('name', newName);
                $(obj).attr('id', "duox" + (ind + 2));
                $(obj).prev().prev().prev().prev().attr('value', varter[(ind + 2)]);
                $(obj).prev().prev().text(varter[(ind + 2)]);

                layedit.build("duox" + (ind + 2), {
                    tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right']
                });
            }
            if (oldAttrNames) {
                var front = oldAttrNames.substring(0, oldAttrNames.indexOf("[") + 1);
                var back = oldAttrNames.substring(oldAttrNames.indexOf("]"), oldAttrNames.length);
                var newName = front + (ind + 2) + back;
                $(obj).prev().prev().prev().prev().attr('name', newName);
            }
        })
        //遍历隐藏框
        var ssse = duoxs.find(".duoxyc");
        $.each(ssse, function (ind, obj) {
            var oldAttrName = $(obj).attr('name');
            if (oldAttrName) {
                var front = oldAttrName.substring(0, oldAttrName.indexOf("[") + 1);
                var back = oldAttrName.substring(oldAttrName.indexOf("]"), oldAttrName.length);
                var newName = front + (ind + 2) + back;
                $(obj).attr('name', newName);
                $(obj).attr('value', varter[ind + 2]);

            }
        })
        form.render();
    }

    //增加填空题
    function addTk() {
        var tks = $(".tk");
        var index = tks.length;
        var i = tks.length - 1;
        var tk = $("<ul class=\"clearfix fl tk\"  style=\"width: 100%;position: relative\">\n" +
            "\t\t\t\t\t\t<label class=\"fl w90\" style=\"float: left\" >填空" + (index + 1) + "</label><input type=\"text\" class=\"tiankong\" name=\"exTkList[" + (i + 1) + "].answerContent\" placeholder=\"请输入内容\">" +
            "<input type=\"hidden\" class='tihao' name=\"exTkList[" + (i + 1) + "].answerAnalysis\" value=\"填空" + (index + 1) + "\"></ul>");

        var b = $("<img src=\"${re.contextPath}/plugin/common/images/30@2x.png\" style=\"position:absolute;top:2px;left:273px;width:20px;height:20px;background-color:#3e7ce7\" onclick=\"del(this)\" alt=\"\" class=\"\">");
        b.click(del);
        tk.append(b)
        $("#tks").append(tk);
    }

    function del(Object) {
        $(this).parent().remove();
        if ($(this).parent().length > 0) {
            var ssses = $("#tks").find(".tiankong");
            if (ssses.length > 0) {
                formatFBInd();
            }
        }
    }

    //删除后剩余重新排序
    function formatFBInd() {
        var ssses = $("#tks").find(".tiankong");
        $.each(ssses, function (ind, obj) {
            var oldAttrName = $(obj).attr('name');
            if (oldAttrName) {
                var front = oldAttrName.substring(0, oldAttrName.indexOf("[") + 1);
                var back = oldAttrName.substring(oldAttrName.indexOf("]"), oldAttrName.length);
                var newName = front + (ind + 1) + back;
                $(obj).attr('name', newName);
                //更改 分包编号x
                $(obj).prev().html("填空" + (ind * 1 + 2));
            }
        })
        //遍历隐藏框
        var ssse = $("#tks").find(".tihao");
        $.each(ssse, function (ind, obj) {
            var oldAttrName = $(obj).attr('name');
            if (oldAttrName) {
                var front = oldAttrName.substring(0, oldAttrName.indexOf("[") + 1);
                var back = oldAttrName.substring(oldAttrName.indexOf("]"), oldAttrName.length);
                var newName = front + (ind + 1) + back;
                $(obj).attr('name', newName);
                $(obj).attr('value', "填空" + (ind * 1 + 2));

            }
        })
    }


</script>
</body>

</html>
